package com.cgbl.cg.adapter

import android.os.Bundle
import androidx.appcompat.widget.AppCompatImageView
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.ColorUtils
import com.blankj.utilcode.util.SizeUtils
import com.blankj.utilcode.util.SpanUtils
import com.cgbl.cg.R
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.robot.base.configs.AppConstants
import com.robot.base.model.CourseBean
import com.robot.base.util.arouter.ARouterUtil
import com.robot.base.utils.pic.ImageLoaderUtils

class MoreCourseAdapter(val visit: Boolean = true, val titleVisit: Boolean = true) :
    BaseQuickAdapter<CourseBean, BaseViewHolder>(R.layout.app_item_more_course) {
    override fun convert(holder: BaseViewHolder, item: CourseBean) {
        if (!visit) {
            holder.setGone(R.id.item_tv_3, true)
        }
        if (!titleVisit) {
            holder.setGone(R.id.item_iv_heat, true)
                .setGone(R.id.item_tv_1, true)
        }

        holder.setText(
            R.id.item_tv_1,
            "${item.countStudy}人在学·${item.classHour}小时"
        )
            .setText(R.id.item_tv_name, item.courseName)
            .setText(R.id.item_tv_label, item.className)
            .setText(R.id.item_tv_3, "￥${item.rulingPrice?:"0.00"}")
            .setText(R.id.item_tv_2, "￥${item.coursePrice?:"0.00"}")

        if(item.free == "2"){
            holder.setGone(R.id.item_tv_3, true)
                    SpanUtils.with(holder.getView(R.id.item_tv_2)).append("VIP限免")
                    .setForegroundColor(ColorUtils.getColor(R.color.app_color_ffc063)).create()
        }else{
            holder.setGone(R.id.item_tv_3, false)
            SpanUtils.with(holder.getView(R.id.item_tv_2)).append("￥${item.coursePrice?:"0.00"}")
                .setForegroundColor(ColorUtils.getColor(R.color.app_color_cc2d2d)).create()
        }

        holder.itemView.setOnClickListener {
            ARouterUtil.goToActivityWithBundle(AppConstants.Router.Mine.A_MINE_COURSE_PROFILE,
                Bundle().apply {
                    putString(AppConstants.BundleKey.ID, item.courseId)
                })
        }

        val ivImg = holder.getView<AppCompatImageView>(R.id.item_iv_img)
        ImageLoaderUtils.displayRound(context, ivImg, item.courseCoverImage, 10)
    }
}